/*刷新表格*/
function refresh(){

    var table = $('.table').DataTable();
    table.ajax.reload(null,false);// 刷新表格数据，分页信息不会重置
}

/*时间转换*/
function date(data){
    if(data==null||data==""){
        return "";
    }
    var time = new Date(data);
    var y = time.getFullYear();//年
    var m = time.getMonth() + 1;//月
    if (m >= 0 && m <= 9) {
        m = "0" + m;
    }
    var d = time.getDate();//日
    if (d >= 0 && d <= 9) {
        d = "0" + d;
    }
    var h = time.getHours();//时
    if (h >= 0 && h <= 9) {
        h = "0" + h;
    }
    var mm = time.getMinutes();//分
    if (mm >= 0 && mm <= 9) {
        mm = "0" + mm;
    }
    return (y+"-"+m+"-"+d+" "+h+":"+mm);
}


function dateymd(data){
    if(data==null||data==""){
        return "";
    }
    var time = new Date(data);
    var y = time.getFullYear();//年
    var m = time.getMonth() + 1;//月
    if (m >= 0 && m <= 9) {
        m = "0" + m;
    }
    var d = time.getDate();//日
    if (d >= 0 && d <= 9) {
        d = "0" + d;
    }
    return (y+"-"+m+"-"+d);
}

/*时间转换2*/
function dateAll(data){
    if(data==null||data==""){
        return "";
    }
    var time = new Date(data);
    var y = time.getFullYear();//年
    var m = time.getMonth() + 1;//月
    if (m >= 0 && m <= 9) {
        m = "0" + m;
    }
    var d = time.getDate();//日
    if (d >= 0 && d <= 9) {
        d = "0" + d;
    }
    var h = time.getHours();//时
    if (h >= 0 && h <= 9) {
        h = "0" + h;
    }
    var mm = time.getMinutes();//分
    if (mm >= 0 && mm <= 9) {
        mm = "0" + mm;
    }
    var ss = time.getSeconds();//秒
    if (ss >= 0 && ss <= 9) {
        ss = "0" + ss;
    }
    return (y+"-"+m+"-"+d+" "+h+":"+mm+":"+ss);
}


// 获得今天的起点
function getTodayStart() {
    var dd = new Date();
    dd.setHours(0)
    dd.setMinutes(0)
    dd.setSeconds(0)
    var day =  dateAll(dd.getTime())
    return day;
};
// 获得今天的起点
function getTodayStartTimeStamp() {
    var dd = new Date();
    dd.setHours(0)
    dd.setMinutes(0)
    dd.setSeconds(0)
    return dd.getTime();
};
// 获得今天的终点时间
function getTodayEnd() {
    var dd = new Date();
    dd.setHours(23)
    dd.setMinutes(59)
    dd.setSeconds(59)
    var day =  dateAll(dd.getTime())
    return day;
};
// 获得今天的起点
function getTodayEndTimeStamp() {
    var dd = new Date();
    dd.setHours(23)
    dd.setMinutes(59)
    dd.setSeconds(59)
    return dd.getTime();
};

function getWeekStart() {
    var now = new Date();
    var nowDay = now.getDate();              //当前日
    var nowMonth = now.getMonth();           //当前月
    var nowYear = now.getFullYear();             //当前年
    var nowDayOfWeek = now.getDay();
    if (nowDayOfWeek ==0) nowDayOfWeek = 7
    var weekEndDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek +1);
    weekEndDate.setHours(0)
    weekEndDate.setMinutes(0)
    weekEndDate.setSeconds(0)
    var day =  dateAll(weekEndDate.getTime())
    return day;
};

function getWeekEnd() {
    var now = new Date();
    var nowDay = now.getDate();              //当前日
    var nowMonth = now.getMonth();           //当前月
    var nowYear = now.getFullYear();             //当前年
    var nowDayOfWeek = now.getDay();
    if (nowDayOfWeek ==0) nowDayOfWeek = 7
    var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek) +1);
    weekEndDate.setHours(23)
    weekEndDate.setMinutes(59)
    weekEndDate.setSeconds(59)
    var day =  dateAll(weekEndDate.getTime())
    return day;
};



function getMonthStart() {
    var now = new Date();
    var nowMonth = now.getMonth();           //当前月
    var nowYear = now.getFullYear();             //当前年
    var firstDay = new Date(nowYear,nowMonth, 1);

    firstDay.setHours(0)
    firstDay.setMinutes(0)
    firstDay.setSeconds(0)
    var day =  dateAll(firstDay.getTime())
    return day;
};

function getMonthEnd() {
    var now = new Date();
    var nowMonth = now.getMonth();           //当前月
    var nowYear = now.getFullYear();             //当前年
    var firstDay = new Date(nowYear,nowMonth+1, 0);

    firstDay.setHours(23)
    firstDay.setMinutes(59)
    firstDay.setSeconds(59)
    var day =  dateAll(firstDay.getTime())
    return day;
};
function getYearStart() {
    var now = new Date();
    now.setMonth(0)
    now.setDate(1)
    now.setHours(0)
    now.setMinutes(0)
    now.setSeconds(0)
    var day =  dateAll(now.getTime())
    return day;
};

function getYearEnd() {
    var now = new Date();
    now.setMonth(11)
    now.setDate(31)
    now.setHours(23)
    now.setMinutes(59)
    now.setSeconds(59)
    var day =  dateAll(now.getTime())
    return day;
};
